package cn.itcast.web.exceptions;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 自定义异常处理
 */
public class CustomExceptionResovler implements HandlerExceptionResolver{

    /**
     * 该方法就可以处理异常
     * @param httpServletRequest
     * @param httpServletResponse
     * @param o
     * @param e
     * @return
     */
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {

        //把错误信息转到error.jsp显示

        ModelAndView mv = new ModelAndView();
        mv.addObject("errorMsg","发生异常："+e.getMessage());
        mv.setViewName("error");

        return mv;
    }
}
